package com.cn.demo.springboot.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.demo.springboot.shiro.annotation.BodyPermissions;

@Controller
//@Slf4j
@RequestMapping("/shiro")
public class ShiroController {
	private final static Logger log = LoggerFactory.getLogger(ShiroController.class);
	@RequestMapping("/a")
	public String a() {
		log.debug("shiro - a");
		return "shiro";
	}
	
	/**
	 * 这个方法需要admin权限才可以访问
	 */
	@RequestMapping("testMethodPermission")
	@RequiresPermissions(value = "testMethodPermission")
	@ResponseBody
	@BodyPermissions(code = "testMethodPermission",menuCode="freemarker/a",name = "testMethodPermission权限")
	public String testMethodPermission() {
		log.debug("testMethodPermission SecurityUtils.getSubject() = {}",SecurityUtils.getSubject());
		return "testMethodPermission Success";
	}
	
	
	/**
	 * 这个方法需要admin权限才可以访问
	 */
	@RequestMapping("testMethodPermission1")
	@RequiresPermissions(value = "admin")
	public String testMethodPermission1() {
		log.debug("testMethodPermission SecurityUtils.getSubject() = {}",SecurityUtils.getSubject());
		return "index";
	}

}
